//
//  MessagesViewController.m
//  MessagesExtension
//
//  Created by Agensn on 2017/2/17.
//  Copyright © 2017年 🌹Agensn_Master🌹. All rights reserved.
//

#import "MessagesViewController.h"


@interface MessagesViewController ()

@property(nonatomic,strong)NSMutableArray *theArr;


@end

@implementation MessagesViewController

-(NSMutableArray *)theArr{
    if (!_theArr) {
        _theArr = [NSMutableArray array];
    }
    return _theArr;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    //背景颜色
    self.stickerBrowserView.backgroundColor = [UIColor grayColor];
    //数据源
    [self loadData];

}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

-(void)loadData{
    //图片名称数组
    NSArray *arr = @[@"catjump",@"ear",@"eyes",@"glasses",@"grass",@"halo",@"hat",@"moustache",@"necklace",@"nose"];
//    遍历添加到数组
    for (NSString *str in arr) {
        NSURL *url = [[NSBundle mainBundle]URLForResource:str withExtension:@".png"];
        //创建贴纸
        MSSticker *sticker = [[MSSticker alloc]initWithContentsOfFileURL:url localizedDescription:str error:nil];
        //添加到数组
        [self.theArr addObject:sticker];
    }
}
//数目
-(NSInteger)numberOfStickersInStickerBrowserView:(MSStickerBrowserView *)stickerBrowserView{
    return _theArr.count;
}
//内容
-(MSSticker *)stickerBrowserView:(MSStickerBrowserView *)stickerBrowserView stickerAtIndex:(NSInteger)index{
    return _theArr[index];
}

#pragma mark - Conversation Handling

-(void)didBecomeActiveWithConversation:(MSConversation *)conversation {
    // Called when the extension is about to move from the inactive to active state.
    // This will happen when the extension is about to present UI.
    
    // Use this method to configure the extension and restore previously stored state.
}

-(void)willResignActiveWithConversation:(MSConversation *)conversation {
    // Called when the extension is about to move from the active to inactive state.
    // This will happen when the user dissmises the extension, changes to a different
    // conversation or quits Messages.
    
    // Use this method to release shared resources, save user data, invalidate timers,
    // and store enough state information to restore your extension to its current state
    // in case it is terminated later.
}

-(void)didReceiveMessage:(MSMessage *)message conversation:(MSConversation *)conversation {
    // Called when a message arrives that was generated by another instance of this
    // extension on a remote device.
    
    // Use this method to trigger UI updates in response to the message.
}

-(void)didStartSendingMessage:(MSMessage *)message conversation:(MSConversation *)conversation {
    // Called when the user taps the send button.
}

-(void)didCancelSendingMessage:(MSMessage *)message conversation:(MSConversation *)conversation {
    // Called when the user deletes the message without sending it.
    
    // Use this to clean up state related to the deleted message.
}

-(void)willTransitionToPresentationStyle:(MSMessagesAppPresentationStyle)presentationStyle {
    // Called before the extension transitions to a new presentation style.
    
    // Use this method to prepare for the change in presentation style.
}

-(void)didTransitionToPresentationStyle:(MSMessagesAppPresentationStyle)presentationStyle {
    // Called after the extension transitions to a new presentation style.
    
    // Use this method to finalize any behaviors associated with the change in presentation style.
}

@end
